package com.ruoyi.bnt.controller;

import java.util.List;

import com.ruoyi.common.utils.uuid.UUID;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bnt.domain.BntArticleinfo;
import com.ruoyi.bnt.service.IBntArticleinfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程详情（文章）Controller
 * 
 * @author yyj
 * @date 2020-10-03
 */
@Controller
@RequestMapping("/bnt/course/articleinfo")
public class BntArticleinfoController extends BaseController
{
    private String prefix = "bnt/course/articleinfo";

    @Autowired
    private IBntArticleinfoService bntArticleinfoService;

    @RequiresPermissions("bnt:articleinfo:view")
    @GetMapping()
    public String articleinfo()
    {
        return prefix + "/articleinfo";
    }

    /**
     * 查询课程详情（文章）列表
     */
    @RequiresPermissions("bnt:articleinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BntArticleinfo bntArticleinfo)
    {
        startPage();
        List<BntArticleinfo> list = bntArticleinfoService.selectBntArticleinfoList(bntArticleinfo);
        return getDataTable(list);
    }

    /**
     * 导出课程详情（文章）列表
     */
    @RequiresPermissions("bnt:articleinfo:export")
    @Log(title = "课程详情（文章）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BntArticleinfo bntArticleinfo)
    {
        List<BntArticleinfo> list = bntArticleinfoService.selectBntArticleinfoList(bntArticleinfo);
        ExcelUtil<BntArticleinfo> util = new ExcelUtil<BntArticleinfo>(BntArticleinfo.class);
        return util.exportExcel(list, "articleinfo");
    }

    /**
     * 新增课程详情（文章）
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @GetMapping("/add/{parentId}")
    public String add(@PathVariable("parentId") String parentId, ModelMap mmap)
    {
        mmap.put("parentId", parentId);
        return prefix + "/add";
    }

    /**
     * 新增保存课程详情（文章）
     */
    @RequiresPermissions("bnt:articleinfo:add")
    @Log(title = "课程详情（文章）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BntArticleinfo bntArticleinfo)
    {
        if(bntArticleinfo.getId() == null || bntArticleinfo.getId().isEmpty())
            bntArticleinfo.setId(UUID.randomUUID().toString());
        return toAjax(bntArticleinfoService.insertBntArticleinfo(bntArticleinfo));
    }

    /**
     * 修改课程详情（文章）
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BntArticleinfo bntArticleinfo = bntArticleinfoService.selectBntArticleinfoById(id);
        mmap.put("bntArticleinfo", bntArticleinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程详情（文章）
     */
    @RequiresPermissions("bnt:articleinfo:edit")
    @Log(title = "课程详情（文章）", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BntArticleinfo bntArticleinfo)
    {
        return toAjax(bntArticleinfoService.updateBntArticleinfo(bntArticleinfo));
    }

    /**
     * 删除课程详情（文章）
     */
    @RequiresPermissions("bnt:articleinfo:remove")
    @Log(title = "课程详情（文章）", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bntArticleinfoService.deleteBntArticleinfoByIds(ids));
    }
}
